// Playground - noun: a place where people can play

import Cocoa


/*********************************************************************
 * The Swift Language Learning  Chapter 08: Classes and Structures
 *********************************************************************/

struct Resolution {
	var width = 0
	var height = 0
}

let ra = Resolution(width: 100, height: 100)


class Camare{
	var resolution = Resolution()
	var vendor = "Sony"
}


/*
 *Copy Behavor
 */

//Dictionary
var ages = ["Peter": 23, "Wei": 35, "Anish": 65, "Katya": 19]
var copiedAges = ages //deep copy, value types are also copy, unlike NSDictionary

copiedAges["Peter"] = 24
ages["Peter"]


let camare = Camare()

let camareb = Camare()
camareb.vendor = "Pasonic"

var cameras = ["a":camare]
var copiedCameras = cameras

cameras["a"] = camareb
copiedCameras["a"] //not changed. deep copy the reference,but not the class instance


//Array
var a = [1,2,3]
var b = a //slow copied
var c = a

a[0] = 5

a[0]
b[0]
c[0]

a += 3 //a is a new copy. copy beheviors are like Dictionary
b
c


b.unshare() //do copy if it's not unshared
b[0] = 8

b
c

if b===c {
	b
}

var d = b.copy() //copy right now
d[0] = -3
b
d






















